package top.gcl.quartz;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import top.gcl.dao.GoodsMapper;
import top.gcl.entity.Goods;
import top.gcl.redis.RedisUtil;

import javax.annotation.Resource;
import java.util.List;

public class Redis2MysqlJob extends QuartzJobBean {

    @Resource
    private RedisUtil redisUtil;

    @Resource
    private GoodsMapper mapper;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<Goods> list=mapper.list();
        for(Goods goods:list){
            String id=goods.getId();
            String redisKeyGoodsLike="goods_like_"+id;
            Object likeRedis=redisUtil.get(redisKeyGoodsLike);
            mapper.updateLikeById(id, (Integer) likeRedis);
            System.out.println(String.format("mysql==id:%s  like  更新为：%s", id,likeRedis));
        }


    }
}
